//
//  ZJRecFirstTravelTableViewCell.m
//  BreadTravel
//
//  Created by 张健 on 15/12/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ZJRecFirstTravelTableViewCell.h"

@implementation ZJRecFirstTravelTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setView];
    }
    return self;
}

- (void)setView{
    
    self.cover_image = [[UIImageView alloc]init];
    self.cover_image.backgroundColor = [UIColor grayColor];
    self.cover_image.layer.masksToBounds = YES;
    self.cover_image.layer.cornerRadius = 10;
    [self.contentView addSubview:self.cover_image];
    [self.cover_image mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(WIDTH-30);
        make.height.mas_equalTo(190);
    }];
    
    UIImageView *bgImageView = [[UIImageView alloc]init];
    bgImageView.image = [UIImage imageNamed:@"trips_cover_mask.png"];
    [self.cover_image addSubview:bgImageView];
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.cover_image);
        make.top.equalTo(self.cover_image);
        make.bottom.equalTo(self.cover_image);
    }];
    
    self.name = [[UILabel alloc]init];
    self.name.numberOfLines = 0;
    self.name.textColor = [UIColor whiteColor];
    self.name.font = [UIFont systemFontOfSize:19];
    [self.cover_image addSubview:self.name];
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.and.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];
    
    self.last_day = [[UILabel alloc]init];
    self.last_day.textColor = [UIColor whiteColor];
    self.last_day.font = [UIFont systemFontOfSize:12];
    [self.cover_image addSubview:self.last_day];
    [self.last_day mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.name.mas_bottom).offset(5);
        make.left.equalTo(self.name);
        make.height.mas_equalTo(15);
    }];
    
    self.day_count = [[UILabel alloc]init];
    self.day_count.textColor = [UIColor whiteColor];
    self.day_count.font = [UIFont systemFontOfSize:12];
    [self.cover_image addSubview:self.day_count];
    [self.day_count mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.last_day);
        make.left.equalTo(self.last_day.mas_right).offset(5);
        make.height.mas_equalTo(15);
    }];
    
    self.view_count = [[UILabel alloc]init];
    self.view_count.textColor = [UIColor whiteColor];
    self.view_count.font = [UIFont systemFontOfSize:12];
    [self.cover_image addSubview:self.view_count];
    [self.view_count mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.day_count);
        make.left.equalTo(self.day_count.mas_right).offset(5);
        make.height.mas_equalTo(15);
    }];
    
    self.popular_place_str = [[UILabel alloc]init];
    self.popular_place_str.font = [UIFont systemFontOfSize:12];
    self.popular_place_str.textColor = [UIColor whiteColor];
    [self.cover_image addSubview:self.popular_place_str];
    [self.popular_place_str mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.last_day);
        make.top.equalTo(self.last_day.mas_bottom).offset(5);
        make.right.mas_equalTo(20);
    }];
    
    
    self.avatarImageView = [[UIImageView alloc]init];
    self.avatarImageView.backgroundColor = [UIColor redColor];
    self.avatarImageView.layer.masksToBounds = YES;
    self.avatarImageView.layer.cornerRadius = 12.5;
    [self.cover_image addSubview:self.avatarImageView];
    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.cover_image.mas_bottom).offset(-20);
        make.left.equalTo(self.name);
        make.width.mas_equalTo(25);
        make.height.mas_equalTo(25);
    }];
    
    self.writerLabel = [[UILabel alloc]init];
    self.writerLabel.font = [UIFont systemFontOfSize:12];
    self.writerLabel.textColor = [UIColor whiteColor];
    [self.cover_image addSubview:self.writerLabel];
    [self.writerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.avatarImageView.mas_right).offset(10);
        make.bottom.equalTo(self.cover_image.mas_bottom).offset(-25);
        make.right.mas_equalTo(-20);
    }];
    
    
}

-(void)setTableModel:(ZJTableModel *)tableModel{
    
    
    ZJUserModel *userModel = tableModel.userModel;
    
    NSURL *url1 = [NSURL URLWithString:tableModel.cover_image];
    [self.cover_image sd_setImageWithURL:url1 placeholderImage:IMAGE];
    
    NSURL *url2 = [NSURL URLWithString:userModel.avatar_m];
    [self.avatarImageView sd_setImageWithURL:url2 placeholderImage:IMAGE];
    
    self.name.text = tableModel.name;
    self.last_day.text = tableModel.last_day;
    self.day_count.text = [NSString stringWithFormat:@"%ld天",(long)tableModel.day_count];
    self.view_count.text = [NSString stringWithFormat:@"%ld次浏览",(long)tableModel.view_count];
    self.popular_place_str.text = tableModel.popular_place_str;
    self.writerLabel.text = userModel.name;

    
    
}


@end
